4
4
.
.
4
4
.
.
2
2
M
M
o
o
d
d
a
a
l
l
D
D
r
r
a
a
w
w
e
e
r
r
L
L
a
a
y
y
o
o
u
u
t
t
I
I
n
n
f
f
o
o
[
[
R
R
]
]
ModalDrawerLayout is Navigation View that behaves like drawer which you can open and close
● drawerState defines if drawer is opened or closed
● bodyContent defines how to present drawer on the screen when it is closed (front panel)
● drawerContent defines what should be shown on the screen when drawer is opened
E
E
x
x
a
a
m
m
p
p
l
l
e
e
In this example we create single ModalDrawerLayout that displays Text View when opened with a Button to close it.
MainActivity.kt
package com.example.testcompose
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.Text
import androidx.compose.material.*
import androidx.compose.ui.platform.setContent
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val drawerState = rememberDrawerState(DrawerValue.Closed)
ModalDrawerLayout(
drawerState = drawerState,
bodyContent = {
Button(onClick = { drawerState.open() }) { Text("Open Drawer") }
},
drawerContent = {
Text("First item in drawer")
Text("Second item in drawer")
Button(onClick = { drawerState.close() }) { Text("Close Drawer") }
}
)
}
}
}
Open Drawer Opened Drawer